<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
		<style type="text/css">
			.show_img_ul {
				display: flex;
				flex-wrap: wrap;
				align-items: center;
				margin-top: 10px;
			}
			
			.show_img_li {
				text-align: center;
				padding: 10px;
			}
			
			.show_img_li p,
			.show_img_li1 p {
				text-align: center;
				cursor: pointer;
			}
			
			.show_img_li img {
				width: 120px;
				height: 120px;
				margin-bottom: 8px;
			}
			
			.show_img_li1 img {
				width: 300px;
				height: 200px;
				margin-bottom: 8px;
			}
			
			.layui-upload-img {
				width: 92px;
				height: 92px;
				margin: 0 10px 10px 0;
			}
			.layui-upload-img { width: 90px; height: 90px; margin: 0; }
			.layui-elem-quote  { width:100%; left; margin: 10px 0px 0px 0px;}
			.layui-elem-quote  li { width:90px; display: inline-block; margin-right: 5px;}
			.layui-elem-quote  li .layui-input { display: initial; }
			.layui-elem-quote  li a { position: absolute; top: 0; display: block; }
			.layui-elem-quote  li a i { font-size: 24px; background-color: #008800; }   
			#demo2 .item_img img{ width: 90px; height: 90px;}
			#demo2 li{position: relative;margin: 10px.;}
			#demo2 li .operate{ color: #000; display: none;}
			#demo2 li .toleft{ position: absolute;top: 40px; left: 1px; cursor:pointer;}
			#demo2 li .toright{ position: absolute;top: 40px; right: 1px;cursor:pointer;}
			#demo2 li .close{position: absolute;top: -8px; right: -8px;cursor:pointer;}
			#demo2 li:hover .operate{ display: block;}
		</style>
	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<div class="layui-block">
									<label class="layui-form-label">上传者：</label>
									<div class="layui-input-block">
										<input type="text" name="memberid" lay-verify="required" class="layui-input" id="memberid" autocomplete="off" placeholder="上传者" readonly="">
									</div>  
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-block">
									<label class="layui-form-label">文件名称：</label>
									<div class="layui-input-block">
										<input type="text" name="name" lay-verify="required" class="layui-input" id="name" autocomplete="off" placeholder="文件名称">
									</div>  
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-block">
									<label class="layui-form-label">文件链接：</label>
									<div class="layui-input-block">
										<textarea type="text" name="url" class="layui-textarea" id="url" autocomplete="off" ></textarea>
									</div>  
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-block">
									<label class="layui-form-label">文件简介：</label>
									<div class="layui-input-block">
										<textarea type="text" name="intro" class="layui-textarea" id="intro" autocomplete="off" ></textarea>
									</div>  
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-block">
									<label class="layui-form-label">文件备注：</label>
									<div class="layui-input-block">
										<textarea type="text" name="notes" lay-verify="required" class="layui-textarea" id="notes" autocomplete="off"></textarea>
									</div>  
								</div> 
							</div> 
							
							<div class="layui-form-item">
								<label class="layui-form-label">排序：</label>
								<div class="layui-input-block">
									<input type="text" name="oid" class="layui-input" id="oid" autocomplete="off" placeholder="排序">
								</div>  
							</div> 
							
							<div class="layui-form-item">
								<label class="layui-form-label">证据上传：<span style="color: red;">*</span></label>
								<div class="layui-input-block">
									 <div class="layui-upload ">
										  <button type="button" class="layui-btn" id="test2">多文件上传</button> 
										  <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										    预览图：
										    <div class="layui-upload-list" id="demo2">
										    	
										    </div>
										 </blockquote>
										</div>
								</div>
							</div> 
							
							
						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
					 
							
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			var _member = {
				
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					layedit = layui.layedit,
					colorpicker = layui.colorpicker;
				form = layui.form; 
				
				if(_data.id) {
					initdata();
				}
				var img_arr1 = [],//logo_img
					img_arr2 = [],//bg_img
					img_arr3 = [],//num_url
					img_arr4 = [];//upgrade_url 
					
				var files_urls = []
				on_off_show('radio')
				seckill_type_show("option")
				site_union_show("option")
				  

				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.url = img_arr1.join(',');  
					_data.url = files_urls.join(',');  
					
					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id) {
							submitdata(server.sys_file_upload_edit);
						} else {
							delete _data.id
							submitdata(server.sys_file_upload_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.get(server.sys_file_upload_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.file_upload
								
								data.data.url ? createli(data.data.url, 'logo_img', '1') : ''; 
								
								files_urls = data.data.url ? data.data.url.split(','):[]
								for (let i = 0; i < files_urls.length; i++) { 
				                	$('#demo2').append('<li class="item_img" ><a href="'+files_urls[i]+'" style="display: none;"></a><div class="operate"><i class="toleft layui-icon"> </i><i class="toright layui-icon"> </i><i  class="close layui-icon"><img style="height: 16px;width: 16px;" src="../../../../img/del.png"></i></div><img src="' +choose_img(files_urls[i]) + '" class="img" alt="文件" ></li>');
								}
								
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				} 
				
				window.searchdata = function(type) {
					switch(type) {
						case 'shopid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_shop.html',
								end: function() {},
								success: function() {}
							});
							break;
						case 'partner_id':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_partner.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}
				
				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				
				window.getimg = function(data, type) {
					console.log(data);
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'logo_img', type)
								break;
							  
							default:
								break;
						}
					}
				}

				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch (_type) {
							case '1':
								img_arr1.splice(i, 1)
								break; 
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});

				}

				function createli(data, dom, type) {
					// console.log(data);
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						 
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}
				
				var files_urls = []
				//多图片上传
				  upload.render({
				    elem: '#test2'
				    ,url: server.upimg //改成您自己的上传接口
				    ,multiple: true 
					,accept: 'file' //普通文件
				    ,before: function(obj){
				      //预读本地文件示例，不支持ie8
				      obj.preview(function(index, file, result){
				      	loading() 
				       //	$('#demo2').append('<li class="item_img"><div class="operate"><i class="toleft layui-icon"> </i><i class="toright layui-icon"> </i><i  class="close layui-icon"><img style="height: 16px;width: 16px;" src="del.png"></i></div><img src="' + choose_img(result) + '" class="img" alt="文件" ></li>');
				      });
				    }
				    ,done: function(res){
				       if(res.file){
				       		files_urls.push(res.file)
				       		$('#demo2').append('<li class="item_img"><a href="'+res.data.src+'" style="display: none;"></a><div class="operate"><i class="toleft layui-icon"> </i><i class="toright layui-icon"> </i><i  class="close layui-icon"><img style="height: 16px;width: 16px;" src="../../../../img/del.png"></i></div><img src="' + choose_img(res.data.src) + '" class="img" alt="文件" ></li>');
				       }
				       closeloading()
				    }
				  });
				  
			  //点击多图上传的X,删除当前的图片   
			$("body").on("click",".close",function(){
				var li_index=$(this).closest("li").index();
			    $(this).closest("li").remove();
			    files_urls.splice(li_index,1) 
			  });
			  
			  //点击查看当前的图片   
			$("body").on("click",".item_img",function(){
				console.log(this)
				var o = $(this).children('a')[0].href
				//console.log(o) 
				
				if(o.indexOf('.img') > -1 ||o.indexOf('.png') > -1 || o.indexOf('.jpg') > -1 ){
					var img_data = {
						"data": []
					}
					img_data.data.push({
						"src": o
					})
					layer.photos({
						photos: img_data,
						anim: 5  
					});
				} else if(o.indexOf('.txt') > -1 ){ 
					layer.open({
							type: 2,
							title: '查看',
							shadeClose: false,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['90%', '90%'],
							content: o,
							end: function() {},
							success: function() {}
						});
				}else { 
					window.parent.location = o
				}
			});
			function choose_img(url){
		    	let suf = url.substring(url.lastIndexOf('.')+1)
		    	console.log(suf)
		    	switch (suf){
		    		case 'ppt':
		    			return '../../../../img/ppt.png';
	    				break; 
	    			case 'pdf':
		    			return '../../../../img/pdf.png';
	    				break; 
	    			case 'txt':
		    			return '../../../../img/txt.png';
		    			break;
	    			case 'word':
		    			return '../../../../img/word.png';
		    			break;
	    			case 'excel':
		    			return '../../../../img/excel.png';
		    			break;
	    			case 'jpg':
		    			return url;
		    			break;
	    			case 'gif':
		    			return url;
		    			break;
		    		case 'png':
		    			return url;
		    			break;
		    		default:
		    			return '../../../../img/ccommon.png';
		    			break;
	    	}}
				  
				  
			}); 
		</script>
	</body>

</html>